/**
 * mode 通用设置说明
 *  0  : 解析集合页 
 * 数字(1-4...) : 网页解析表   
 * '①' : ①HTV009  '②' : ②迪奥解析 ...
 * */

// 爱奇艺设置
var iqiyi_mode = '⑤';
var iqiyi_coding = '8191'; // (仅③有效)视频编码 ：8191 - H265(可能只有声音没有画面) 8196 - H264(可能没有4K地址)
var iqiyi_Resolution = '800'; // (仅③有效)分辨率：800-4k  600-蓝光  500-超清
// 腾讯设置
var qq_mode = '③';
var qq_sharpness = 'fhd'; // (仅③有效)sd-标清 hd-高清 shd-超清 fhd-蓝光
// 优酷设置
var youku_mode = '③';
// 芒果设置
var mgtv_mode = '③'; // 直链解析推荐① ②, 其他可能不支持
// 咪咕设置
var migu_mode = '④'; // 直链解析推荐① ④ ⑤, 其他可能不支持
var sharpness = 1; // 1-最清 2-最低 3-可选

// 全局网页解析列表(可按格式添加修改)
var parsing_list = [
    '安歌￥https://z1.m1907.cn/?jx=',
    '我爱解析￥https://vip.52jiexi.top/?url=',
    '菜鸟￥https://jiexi.bm6ig.cn/?url=',
    '七彩￥https://v.7cyd.com/vip/?url='
];
var HTV009_pre = [
    'https://user.htv009.com/json?url=',
    'http://5.nmgbq.com/j1/api.php?url=',
    'https://jx.ikancloud.cn/api.php?url=',
    'https://app.tf.js.cn/jxds/api.php?url='
];
// 全局直链解析列表(可按格式添加修改)
var parse_list = [
    `①HTV009￥` + HTV009_pre[Math.floor(Math.random() * 4)] + `￥@lazyRule=.js:eval(fetch('hiker://files/rules/js/g-parse-list.js',{}));var url = HTV009.toUrl(input);url!=''?url:getUrl(input)`,
    `②迪奥￥http://api.1dior.cn/analysis/first/api.php?url=￥@lazyRule=.js:eval(fetch('hiker://files/rules/js/g-parse-list.js',{}));var url = 迪奥.toUrl(input);url!=''?url:getUrl(input)`,
    `③北极XS￥http://beijixs.cn?url=￥@lazyRule=.js:eval(fetch('hiker://files/rules/js/g-parse-list.js',{}));var url = 北极XS.toUrl(input);url!=''?url:getUrl(input)`,
    `④Mao全网￥https://www.cuan.la/m3u8.php?url=￥@lazyRule=.js:eval(fetch('hiker://files/rules/js/g-parse-list.js',{}));var url = Mao全网.toUrl(input);url!=''?url:getUrl(input)`,
    `⑤tv920￥https://yun.tv920.com/vip.php?url=￥@lazyRule=.js:eval(fetch('hiker://files/rules/js/g-parse-list.js',{}));var url = tv920.toUrl(input);url!=''?url:getUrl(input)`,
    `⑥大白￥https://jx.dabaiapi.com/?url=￥@lazyRule=.js:eval(fetch('hiker://files/rules/js/g-parse-list.js',{}));var url = 大白.toUrl(input);url!=''?url:getUrl(input)`
];

var HTV009 = {
    toUrl: function (input) {
        try {
            var json = JSON.parse(fetch(input, {}));
            var url = (json.code == '200' ? json.url + '#.mp4' : '');
            if (url != '') {
                url = (url.indexOf('titan.mgtv') > -1 ? url + ';{Referer@https://mg.nitjvrc.cn}' : url);
            }
            return url;
        } catch (e) {
            return '';
        }
    }
};
var 迪奥 = {
    toUrl: function (input) {
        try {
            var json = JSON.parse(fetch(input.split('url=')[0], { body: 'url=' + input.split('url=')[1], method: 'POST' }));
            var url = (json.code == 200 ? (json.url.indexOf('dis_t=1595745451') > 0 ? '' : json.url + '#.mp4') : '');
            if (url != '') {
                url = (url.indexOf('http') > -1 ? url : 'http:' + url);
            }
            return url;
        } catch (e) {
            return '';
        }
    }
};
var 北极XS = {
    Init: function () {
        if (getVar('VIEWSTATE').length == 0) {
            var beiji_html = fetch('http://beijixs.cn', {});
            putVar({ key: 'VIEWSTATE', value: parseDomForHtml(beiji_html, 'body&&form&&input&&value') });
            putVar({ key: 'EVENTVALIDATION', value: parseDomForHtml(beiji_html, 'body&&form&&input,2&&value') });
        }
    },
    toUrl: function (input) {
        try {
            this.Init();
            var html = fetch('http://beijixs.cn', { body: 'Button1=解析&TextBox4=' + iqiyi_Resolution + '&DropDownList2=' + iqiyi_coding + '&DropDownList1=' + qq_sharpness + '&TextBox1=' + input.split('=')[1] + '&__VIEWSTATE=' + getVar('VIEWSTATE') + '&__EVENTVALIDATION=' + getVar('EVENTVALIDATION'), method: 'POST' });
            var url = parseDom(html, 'body&&video&&source&&src') + '#.mp4';
            return url.indexOf('transcode')>0?'':url;
        } catch (e) {
            return '';
        }

    }
};
var Mao全网 = {
    toUrl: function (input) {
        try {
            var html = fetch(input, {});
            var url = decodeURIComponent(html.split('"url":"')[1].split('"')[0]) + '#.mp4';
            return url.indexOf('http') > -1 ? url : 'http:' + url;
        } catch (e) {
            return '';
        }
    }
};
var tv920 = {
    toUrl: function (input) {
        function lco(t) {
            var a = lcb(1) + t;
            return a.replace(/[\-|\,]/g, '');
        }
        function lcl(x, y) {
            var a = (x & 0xFFFF) + (y & 0xFFFF);
            var b = (x >> 16) + (y >> 16) + (a >> 16);
            return (b << 16) | (a & 0xFFFF);
        }
        function lcc(a, b) {
            return (a << b) | (a >>> (32 - b));
        }
        function lcf(a, b, c, d, x, s, t) {
            return lce((b & c) | ((~b) & d), a, b, x, s, t);
        }
        function lcg(a, b, c, d, x, s, t) {
            return lce((b & d) | (c & (~d)), a, b, x, s, t);
        }

        function lce(q, a, b, x, s, t) {
            return lcl(lcc(lcl(lcl(a, q), lcl(x, t)), s), b);
        }

        function lch(a, b, c, d, x, s, t) {
            return lce(b ^ c ^ d, a, b, x, s, t);
        }
        function lci(a, b, c, d, x, s, t) {
            return lce(c ^ (b | (~d)), a, b, x, s, t);
        }
        function lcb(x) {
            var a = 1732584193;
            var b = -271733879;
            var c = -1732584194;
            var d = 271733878;
            if (x !== '1') {
                for (var i = 0; i < x.length; i += 16) {
                    var a1 = a;
                    var b1 = b;
                    var c1 = c;
                    var d1 = d;
                    a = lcf(a, b, c, d, x[i + 0], 7, -680876936);
                    d = lcf(d, a, b, c, x[i + 1], 12, -389564586);
                    c = lcf(c, d, a, b, x[i + 2], 17, 606105819);
                    b = lcf(b, c, d, a, x[i + 3], 22, -1044525330);
                    a = lcf(a, b, c, d, x[i + 4], 7, -176418897);
                    d = lcf(d, a, b, c, x[i + 5], 12, 1200080426);
                    c = lcf(c, d, a, b, x[i + 6], 17, -1473231341);
                    b = lcf(b, c, d, a, x[i + 7], 22, -45705983);
                    a = lcf(a, b, c, d, x[i + 8], 7, 1770035416);
                    d = lcf(d, a, b, c, x[i + 9], 12, -1958414417);
                    c = lcf(c, d, a, b, x[i + 10], 17, -42063);
                    b = lcf(b, c, d, a, x[i + 11], 22, -1990404162);
                    a = lcf(a, b, c, d, x[i + 12], 7, 1804603682);
                    d = lcf(d, a, b, c, x[i + 13], 12, -40341101);
                    c = lcf(c, d, a, b, x[i + 14], 17, -1502002290);
                    b = lcf(b, c, d, a, x[i + 15], 22, 1236535329);
                    a = lcg(a, b, c, d, x[i + 1], 5, -165796510);
                    d = lcg(d, a, b, c, x[i + 6], 9, -1069501632);
                    c = lcg(c, d, a, b, x[i + 11], 14, 643717713);
                    b = lcg(b, c, d, a, x[i + 0], 20, -373897302);
                    a = lcg(a, b, c, d, x[i + 5], 5, -701558691);
                    d = lcg(d, a, b, c, x[i + 10], 9, 38016083);
                    c = lcg(c, d, a, b, x[i + 15], 14, -660478335);
                    b = lcg(b, c, d, a, x[i + 4], 20, -405537848);
                    a = lcg(a, b, c, d, x[i + 9], 5, 568446438);
                    d = lcg(d, a, b, c, x[i + 14], 9, -1019803690);
                    c = lcg(c, d, a, b, x[i + 3], 14, -187363961);
                    b = lcg(b, c, d, a, x[i + 8], 20, 1163531501);
                    a = lcg(a, b, c, d, x[i + 13], 5, -1444681467);
                    d = lcg(d, a, b, c, x[i + 2], 9, -51403784);
                    c = lcg(c, d, a, b, x[i + 7], 14, 1735328473);
                    b = lcg(b, c, d, a, x[i + 12], 20, -1926607734);
                    a = lch(a, b, c, d, x[i + 5], 4, -378558);
                    d = lch(d, a, b, c, x[i + 8], 11, -2022574463);
                    c = lch(c, d, a, b, x[i + 11], 16, 1839030562);
                    b = lch(b, c, d, a, x[i + 14], 23, -35309556);
                    a = lch(a, b, c, d, x[i + 1], 4, -1530992060);
                    d = lch(d, a, b, c, x[i + 4], 11, 1272893353);
                    c = lch(c, d, a, b, x[i + 7], 16, -155497632);
                    b = lch(b, c, d, a, x[i + 10], 23, -1094730640);
                    a = lch(a, b, c, d, x[i + 13], 4, 681279174);
                    d = lch(d, a, b, c, x[i + 0], 11, -358537222);
                    c = lch(c, d, a, b, x[i + 3], 16, -722521979);
                    b = lch(b, c, d, a, x[i + 6], 23, 76029189);
                    a = lch(a, b, c, d, x[i + 9], 4, -640364487);
                    d = lch(d, a, b, c, x[i + 12], 11, -421815835);
                    c = lch(c, d, a, b, x[i + 15], 16, 530742520);
                    b = lch(b, c, d, a, x[i + 2], 23, -995338651);
                    a = lci(a, b, c, d, x[i + 0], 6, -198630844);
                    d = lci(d, a, b, c, x[i + 7], 10, 1126891415);
                    c = lci(c, d, a, b, x[i + 14], 15, -1416354905);
                    b = lci(b, c, d, a, x[i + 5], 21, -57434055);
                    a = lci(a, b, c, d, x[i + 12], 6, 1700485571);
                    d = lci(d, a, b, c, x[i + 3], 10, -1894986606);
                    c = lci(c, d, a, b, x[i + 10], 15, -1051523);
                    b = lci(b, c, d, a, x[i + 1], 21, -2054922799);
                    a = lci(a, b, c, d, x[i + 8], 6, 1873313359);
                    d = lci(d, a, b, c, x[i + 15], 10, -30611744);
                    c = lci(c, d, a, b, x[i + 6], 15, -1560198380);
                    b = lci(b, c, d, a, x[i + 13], 21, 1309151649);
                    a = lci(a, b, c, d, x[i + 4], 6, -145523070);
                    d = lci(d, a, b, c, x[i + 11], 10, -1120210379);
                    c = lci(c, d, a, b, x[i + 2], 15, 718787259);
                    b = lci(b, c, d, a, x[i + 9], 21, -343485551);
                    a = lcl(a, a1);
                    b = lcl(b, b1);
                    c = lcl(c, c1);
                    d = lcl(d, d1);
                }
                return [a, b, c, d];
            } else {
                return [a, d, c, b];
            }
        }
        function lcd(t) {
            var a = ((t.length + 8) >> 6) + 1;
            var b = new Array(a * 16);
            for (var i = 0; i < a * 16; i++)
                b[i] = 0;
            for (var i = 0; i < t.length; i++)
                b[i >> 2] |= (t.charCodeAt(i) & 0xFF) << ((i % 4) * 8);
            b[i >> 2] |= 0x80 << ((i % 4) * 8);
            b[a * 16 - 2] = t.length * 8;
            return b;
        }
        function lca(t) {
            var a = "0123456789abcdef";
            var b = "";
            for (var i = 0; i < t.length * 4; i++) {
                b += a.charAt((t[i >> 2] >> ((i % 4) * 8 + 4)) & 0xF) + a.charAt((t[i >> 2] >> ((i % 4) * 8)) & 0xF);
            }
            return b;
        }
        try {
            var html = fetch(input.split('url=')[0], { headers: { 'Referer': 'https://api.tv920.com' }, body: 'url=' + input.split('url=')[1], method: 'GET' });
            eval(html.split('<script type="text/javascript">')[1].split('function lc_djs(sj)')[0].replace(/"key.*?,/, '"key":"92a78c8789aaf18358868ba676531f09",'));
            var url = decodeURIComponent(JSON.parse(fetch('https://yun.tv920.com/API.php', { headers: { 'content-type': 'application/x-www-form-urlencoded', 'Referer': 'https://yun.tv920.com' }, body: 'url=' + lc.url + '&token=' + lc.token + '&key=' + lc.key + '&time=' + lc.time, method: 'POST' })).url) + '#.mp4';
            return url.indexOf('http') > -1 ? url : 'https:' + url;
        } catch (e) {
            return '';
        }
    }
};
var 大白 = {
    toUrl: function (input) {
        try {
            var key = fetch(input, {}).split("key: '")[1].split("'")[0];
            var url = decodeURIComponent(JSON.parse(fetch('https://jx.dabaiapi.com/api.php', { headers: { 'content-type': 'application/x-www-form-urlencoded' }, body: 'key=' + key, method: 'POST' })).url) + '#.mp4';
            return url.indexOf('url=') > 0 ? url.split('url=')[1] : url;
        } catch (e) {
            return '';
        }
    }
};
function getUrl(input) {
    var input_arr = input.split('url=');
    for (var i in parse_list) {
        var parse_list_arr = parse_list[i].split('￥');
        if (parse_list_arr[1].indexOf(input_arr[0]) > -1)
            break;
        input = parse_list_arr[1] + input_arr[1];
        var str = 'var url = ' + parse_list_arr[0].substr(1) + '.toUrl("' + input + '")';
        eval(str);
        if (url !== '')
            return url;
    }
    return parsing_list[0] + input_arr[1];
}